package net.wicp.tams.commons.binlog.event;

import net.wicp.tams.commons.Result;
import net.wicp.tams.commons.apiext.ByteUtil;
import net.wicp.tams.commons.binlog.bean.EventBean;
import net.wicp.tams.commons.binlog.constant.EventType;

public class FormatDescription extends AbsEvent {
	private int binlogVersion;
	private String mysqlVersion;
	private long createtime;
	private int eventHeaderLength;

	public FormatDescription(EventBean event) {
		super(event);
	}

	@Override
	public Result parseBody() {
		Result ret = Result.getSuc();
		binlogVersion = ByteUtil.readIntL(readSubByte(2));
		mysqlVersion = ByteUtil.readString(readSubByte(50));
		createtime = ByteUtil.readLongL(readSubByte(4));
		eventHeaderLength = ByteUtil.readIntL(readSubByte(1));
		// 设置事件的头长度
		byte[] rest = readRest();
		EventType[] events = EventType.orderFormat();
		for (int i = 0; i < events.length; i++) {
			events[i].setPostHeaderLength(ByteUtil.toUnsigned(rest[i]));
		}
		return ret;
	}

	public int getBinlogVersion() {
		return binlogVersion;
	}

	public String getMysqlVersion() {
		return mysqlVersion;
	}

	public long getCreatetime() {
		return createtime;
	}

	public int getEventHeaderLength() {
		return eventHeaderLength;
	}

}
